Crochet Patterns

by Antonio Sánchez Chinchón

An R experiment to create images generated by sines, cosines and imagination.

Made with tidyverse

Blog post explaining the experiment: Crochet Patterns

Dedicated to the memory of Pilar, my grandmother

Github repo with more details

# Load the tidyverse
library(tidyverse)

# This function creates an individual pattern
pattern <- function(a, b, c = pi/2, d = pi/5, e = 4) {
  data_frame(
    x = accumulate(1:60, ~.x-sin((.y %% e)*c-ceiling((.y-1)/e)*d), .init = a),
    y = accumulate(1:60, ~.x+cos((.y %% e)*c-ceiling((.y-1)/e)*d), .init = b))
}

# I arrange patterns on a circle
t <- seq(0, 2*pi, length.out = 180)
centers <- data_frame(x = sin(t), y = cos(t))

# To initialize parameters of function pattern
c  <- 0.295
d  <- 1.473
e  <- 17

# This creates the plot
apply(centers, 1, function(r) pattern(a = r[1], 
                                      b = r[2],
                                      c = c,
                                      d = d,
                                      e = e)) %>% 
  bind_rows(.id="df") %>% 
  ggplot() +
  geom_path(aes(x, y, group = df), alpha = 0.05) + 
  coord_fixed()+
  theme_void() -> plot

plot


Compiled: 2019-04-21